package com.n.Internet.test;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 服务器
 *
 * @author Mc.Chai
 * @program: Java基础
 * @create 2021-11-27-15:02 15:02
 */
public class MyServer {
    public static void main(String[] args) throws IOException {
        //定义服务器
        ServerSocket server = new ServerSocket(7777);
        System.out.println("等待客户机的连接......");
        //接入客户端
        Socket currentClient = server.accept();
        //读数据（接收请求）
        InputStreamReader reader = new InputStreamReader(currentClient.getInputStream(), "UTF-8");
        BufferedReader request = new BufferedReader(reader);

        //写数据（返回响应）
        String str=request.readLine();
        System.out.println(str);
        String str2=request.readLine();
        System.out.println(str2);
        System.out.println(str2);
        str=str.toUpperCase();

        //写数据（返回响应）
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(currentClient.getOutputStream(), "UTF-8");
        PrintWriter response = new PrintWriter(outputStreamWriter);
        response.println(str);
        response.flush();

        //关闭服务器
        currentClient.close();
    }
}
